package cn.edu.neosoft.sunbo509.finefood.Adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import java.util.List;

import cn.edu.neosoft.sunbo509.finefood.Bean.CommentBean;
import cn.edu.neosoft.sunbo509.finefood.R;

/**
 * Created by 小博 on 2017/11/15.
 */

public class MycommentAdapter extends RecyclerView.Adapter {
    private Context context;
    private List<CommentBean>list;
    public MycommentAdapter(Context context) {
        this.context = context;
    }

    public void setList(List<CommentBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View item= LayoutInflater.from(context).inflate(R.layout.item_mycomment,parent,false);
        return new Viewholder(item);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        CommentBean date=list.get(position);
        Viewholder viewholder=(Viewholder) holder;
        if(date==null)
            return;
        viewholder.tv_shopname.setText(date.getShopname());
        viewholder.tv_foodname.setText(date.getFoodname());
        viewholder.tv_comment.setText(date.getContent());
        viewholder.tv_commentime.setText(date.getComment_time());
        viewholder.btn_update.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        viewholder.btn_delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
    }

    @Override
    public int getItemCount() {
        if(list==null)
            return 0;
        else
            return list.size();
    }

    public class  Viewholder extends RecyclerView.ViewHolder {
        private TextView tv_shopname,tv_foodname,tv_comment,tv_commentime;
        private Button btn_update,btn_delete;
        public Viewholder(View itemView) {
            super(itemView);
            tv_shopname=(TextView)itemView.findViewById(R.id.tv_shopname);
            tv_foodname=(TextView)itemView.findViewById(R.id.tv_foodname);
            tv_comment=(TextView)itemView.findViewById(R.id.tv_comment);
            tv_commentime=(TextView)itemView.findViewById(R.id.tv_commentime);
            btn_update=(Button)itemView.findViewById(R.id.btn_update);
            btn_delete=(Button)itemView.findViewById(R.id.btn_delete);
        }
    }
}
